from django.forms import Form
from django.forms import fields
from django.forms import widgets
from django.forms.models import ModelChoiceField
from app01 import models


class UserInfoForm(Form):

    name = fields.CharField(required=True,error_messages={'required':'用户名不能为空'})
    email = fields.EmailField(required=True)

    part = fields.ChoiceField()

    # user_type = ModelChoiceField(queryset=models.Department.objects.all())

    def __init__(self,*args,**kwargs):
        super(UserInfoForm,self).__init__(*args,**kwargs)

        self.fields['part'].choices = models.Department.objects.values_list('id','title')

def index(request):
    if request.method == 'GET':
        form = UserInfoForm()
        # return render(''''''')



"""
HTML
    form.name
    form.email
    form.part
"""
"""
问题：新添加的部门信息，无法在form.part中显示
特点：重启之后，显示。
"""